<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="auto">
      <el-form-item label="工单编号" prop="workorderCode">
        <el-input v-model="queryParams.workorderCode" placeholder="请输入工单编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        > -->
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="qualityList" height="calc(100vh - 240px)">
      <el-table-column label="序号" align="center" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工单编号" align="center" prop="workorderCode" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品编码" align="center" prop="productCode" />

      <el-table-column label="产品规格" align="center" prop="productSpec" />
      <el-table-column label="巡检数" align="center" prop="inspectionQuantity" />
      <el-table-column label="不良数" align="center" prop="unInspectionQuantity" />
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleDetails(scope.row)" type="text" size="small"
            >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 查看暂停记录页面 -->
    <el-drawer title="详情" :visible.sync="suspendOpen" size="80%" @close="cancel">
      <el-table :data="detailList">
        <el-table-column label="检验单id" align="center" prop="inspectionId" />
        <el-table-column label="检验类型" align="center" prop="indexType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.mes_index_type" :value="scope.row.indexType" />
          </template>
        </el-table-column>
        <el-table-column label="检验项名称" align="center" prop="indexName" />
        <el-table-column label="检验项结果" align="center" prop="checkResult">
          <template slot-scope="scope">
            <span v-show="scope.row.checkResult === 0">不合格</span>
            <span v-show="scope.row.checkResult === 1">合格</span>
          </template>
        </el-table-column>
      </el-table>
    </el-drawer>
  </div>
</template>

<script>
import { listQuality, detailQuality } from "@/api/mes/pro/qualityAnalysis.js";
export default {
  name: "qualityAnalysis",
  dicts: ['mes_index_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workorderCode: null,
      },
      suspendOpen: false,
      qualityList: [],
      detailList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleQuery() {
      this.getList()
    },
    /** 查询生产报工记录列表 */
    getList() {
      this.loading = true;
      listQuality(this.queryParams)
        .then((response) => {
          this.loading = false;
          if (response.rows && response.rows.length) {
            this.qualityList = response.rows;
            this.total = response.total;
          } else {
            this.qualityList = [];
            this.total = 0;
          }
        })
        .catch((err) => {
          this.qualityList = [];
          this.total = 0;
          this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    //查看详情
    handleDetails(row) {
      this.detailList = [];
      this.suspendOpen = true
      detailQuality(row.workorderCode).then(response => {
        if (response.data && response.data.length) {
          this.detailList = response.data;
        }
      })
    },
  },
};
</script>
